static var mSpeed	: float = 3.0; 	// Move speed
static var rSpeed	: float = 300.0;// Rotation speed
static var jSpeed	: float = 3.0;	// Jump speed
static var gravity	: float = 10.0;	// Gravity speed

static var cam : int;
var view: changeView;

private var controller : CharacterController;
private	var direction : Vector3 = Vector3.zero;

function Awake()
{
	// player's rotation is not affected by external factors
	// only unless "transform.rotate" is explicitly called.
	rigidbody.freezeRotation = true;
	
	// attach Character Controller to script
	if(!controller)
		gameObject.AddComponent("CharacterController");
	
	controller = GetComponent(CharacterController);

}

function Start()
{
	// set the variable view to the changeView script found on the GameObject Camera2D
	view = GameObject.Find("pCharacter").GetComponent(changeView);
	
	// set cam to that of the startCamera in the changeView Script
	cam = view.startCamera;
}

// Use FixedUpdate rather than Update because of how Time.DeltaTime works
function FixedUpdate()
{

	var rotationX : float;
	var rotationY : float;
	
	// get update on current active camera
	cam = view.startCamera;
	
	if(controller.isGrounded)
	{
		// 2D Perspective
		if(cam == 1)
		{			
			// Get input vector from keyboard
			direction
			= new Vector3(Input.GetAxis("Horizontal"), 0, 0);
			
			// Jump
			if(Input.GetButton("Jump"))
				direction.y = jSpeed;
		}
		
		// 3D Perspective
		if(cam == 2 || cam == 3)
		{		
			// Get input vector from keyboardis.
			direction
			= new Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
			
			// transform object in direction by speed
			direction = transform.TransformDirection(direction);
			direction *= mSpeed;
			
			// Rotation
			rotationX = Input.GetAxis("Mouse X") * rSpeed;
			rotationX *= Time.deltaTime;
			transform.Rotate(0, rotationX, 0);
	
			// Jump
			if(Input.GetButton("Jump"))
				direction.y = jSpeed;
		}
	}
	
	// Apply Gravity
	direction.y -= gravity * Time.deltaTime;
	
	// Move Controller
	var controller : CharacterController
	= GetComponent(CharacterController);
	
	// Move Player Object
	var move = controller.Move(direction * mSpeed * Time.deltaTime);

}